package zpf.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import zpf.entity.User;
import zpf.feign.UserFeignClient;

import java.util.Random;

/**
 * @ClassName: MovieFeignController
 * @Description: 电影 Feign 控制器，通过 Feign 访问远端服务
 * @Autor: ZPF
 * @Date: 2021/1/13 11:22
 **/
@RestController
public class MovieFeignController {

    @Autowired
    private UserFeignClient userFeignClient;

    @GetMapping("/movie/{id}")
    public User findById(@PathVariable Long id) {
        return userFeignClient.findById(id);
    }

    @GetMapping("/movie/user")
    public User postUser(User user){
        Random random = new Random();
        User tmpUser = new User();
        long id = (long) random.nextInt(100);
        tmpUser.setId(id);
        tmpUser.setName("TempUser" + id);
        tmpUser.setAge((short) id);

        return userFeignClient.postUser(tmpUser);
    }

}
